In many computer applications, variables e.g. counters are used to signify various states of the application. Consider, for example, a one-byte-long counter (ranging over the values 0-255) that stands for a time stamp assigned to objects in a computer application. The counter is initialized to the value 0 and during normal course of operation of the application, the value of the time stamp is assigned to various objects and then the counter is incremented all as stipulated by the application.
When the counter value equals 255 and is then subject to increment, an overflow event occurs since, obviously, the value 256 cannot be represented in an 8-bit-long counter. A naive approach to handle the overflow event is to extend the counter to, say, two bytes, and thereby extending the range of values up to 65535. This naive solution not only complicates the application (as it m.ay be in some processing machines more time consuming to handle a two-byte-long counter than a one-byte-long counter), but also postpones rather than solves the problem. Thus, the counter will eventually be set to 65335 and in the next increment an overflow event occurs.
It is also impossible to simply reset the counter and to start the counting all over again, since the values 0-255 (or at least some of them) have already been used previously. Thus, for example, in the case of a time stamp, the same value x cannot be used to signify a first time (obtained in the first round of counting) and a second, later, time (obtained In the second round of counting).
The present invention concerns an overflow event in applications where a counter sets first and second counter values to respective first and second objects In the application program. A given action should be taken when the first counter values are larger than or equal to the second counter values. One out of any variants where this condition is encountered is in an application for garbage collection of memory objects that reside in a so called old area of a memory heap (herein garbage collection application). The specified technique is disclosed in a co-pending U.S. patent application Ser. No. 09/139,754 assigned to the present applicant and filed simultaneously to the present application. The contents of U.S. patent application Ser. No. 09/139,754 are incorporated herein by reference.
Without going into unnecessary details, in the specified garbage collection application a counter (8-bit-long) that signifies a garbage collection cycle is initialized to 0 or 1 and is than incremented after each cycle. A first counter value of the counter (i.e. garbage collection cycle) is set to a first object (designated as cards) when a first condition is met, and a second counter value is set to a second object (designated as cars) when a second condition is met.
A certain action (in this specific example the action being "perform a given update in a certain data structure") is applied to the second objects in respect of all first objects having associated therewith a cycle value larger than the cycle value of the first object.
The dilemma discussed above is encountered in the case of overflow i.e. the counter has the value of 255 and should be incremented. Put differently, all 255 values are used by either cards and/or cars, and there are no more free values for future use. The above mentioned naive solutions are, obviously, unsatisfactory.
There is, accordingly, a need in the art to provide a satisfactory solution for handling overflow events in applications of the kind discussed above.